package com.dyna.cp.binlog;

import com.dyna.constants.StringPool;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import java.util.Arrays;
import java.util.List;

@Data
@Component
@ConfigurationProperties(prefix = "binlog.datasource")
public class BinLogConstants {

    // 主机
    private String host;

    // 端口
    private int port;

    // 用户名
    private String username;

    // 密码
    private String passwd;

    // 表
    private String table;
    private List<String> tables;

    // 客户端id
    private Integer serverId;

    // 是否启动binlog监听开关
    private Boolean startFlag;

    public List<String> getTables() {
        // 支持以逗号分割的形式填写表
        if (StringUtils.hasText(table)){
            tables = Arrays.asList(table.split(StringPool.COMMA));
        }
        return tables;
    }
}
